var t = getApp(), e = void 0;

Page({
    data: {
        phone_number: "",
        second: 60,
        notbind: !1,
        code: ""
    },
    phoneInput: function(t) {
        this.setData({
            phone_number: t.detail.value
        });
    },
    codeInput: function(t) {
        this.setData({
            code: t.detail.value
        });
    },
    getCode: function() {
        "" == this.data.phone_number ? wx.showToast({
            title: "请输入手机号",
            icon: "none"
        }) : (wx.showLoading({
            title: "获取中",
            mask: !0
        }), t.com.post("wx/user/code", {
            phone_number: this.data.phone_number
        }, function(t) {
            if (wx.hideLoading(), 0 === t.errno) {
                e.setData({
                    second: 60,
                    notbind: !0
                });
                var n = setInterval(function() {
                    e.data.second > 0 ? e.setData({
                        second: e.data.second - 1
                    }) : (e.setData({
                        second: 60,
                        notbind: !1
                    }), clearInterval(n));
                }, 1e3);
            }
        }));
    },
    onLoad: function(t) {
        e = this;
    },
    submit: function(n) {
        var o = n.detail.rawData;
        11 != this.data.phone_number.length ? wx.showToast({
            title: "请输入11位手机号",
            icon: "none"
        }) : "" == this.data.code ? wx.showToast({
            title: "请输入验证码",
            icon: "none"
        }) : (wx.showLoading({
            title: "请稍等",
            mask: !0
        }), t.com.post("wx/user/bindPhone", {
            phone_number: this.data.phone_number,
            code: this.data.code,
            user: o
        }, function(t) {
            wx.hideLoading(), 0 == t.errno && (wx.showToast({
                title: "更换成功",
                duration: 1e3,
                mask: !0
            }), wx.setStorage({
                key: "phone",
                data: e.data.phone_number,
                success: function() {
                    setTimeout(function() {
                        wx.navigateBack({
                            delta: 1
                        });
                    }, 1e3);
                }
            }));
        }));
    }
});